package com.atfcm.stack;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @Author 96534
 * @create 2025/3/21 16:07
 */
public class T_155_最小栈 {
    //  1 2 3



}


class MinStack {
    Deque<Integer> stack = new LinkedList();
    Deque<Integer>  minStack = new LinkedList();

    public MinStack() {

    }

    public void push(int val) {
        stack.push(val);
        if(minStack.isEmpty()){
            minStack.push(val);
        }else {
            if(val < minStack.peek()){
                minStack.push(val);
            }else {
                minStack.push(minStack.peek());
            }
        }
    }

    public void pop() {
        minStack.pop();
        stack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
